package highscore;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;


public class DB 
{
	private static Connection	conn	= null;
	private static Statement	stmt	= null;
	private static boolean 		connected = false;

	public static void connect()
	{
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("http://zmtn.dyndns-web.com","mcawesome","plant");
			stmt = conn.createStatement();
			setConnected(true);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static ArrayList<String[]> getTableData(String query)
	{
		ArrayList<String[]> vOA = new ArrayList<String[]>();
		
		ResultSetMetaData rSM;
		
		try 
		{
			ResultSet rS = stmt.executeQuery(query);
			rSM = rS.getMetaData();
			int columns = rSM.getColumnCount();
			while (rS.next()) 
			{
				String[] oA = new String[columns];
				for (int i = 1; i <= columns; i++) 
				{
					//System.out.println(rS.getObject(i).toString());
					oA[i - 1] = rS.getObject(i).toString();
				}
				vOA.add(oA);
			}
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
		return vOA;
		
	}

	public static void setConnected(boolean connected) 
	{
		DB.connected = connected;
	}

	public static boolean isConnected() 
	{
		return connected;
	}
}
